package com.gemini.main.common.bean;

public class ResultGenerator {
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    // 生成成功码，并且不返回data数据
    public static Result genSuccessResult() {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMsg(DEFAULT_SUCCESS_MESSAGE);
    }

    // 生成成功码，返回data数据
    public static Result genSuccessResult(Object data) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMsg(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);
    }

    // 生成错误码，说明错误原因，无返回数据
    // 也可以将code代码返回，并且和前端交互好code的含义
    public static Result genFailResult(String msg) {
        return new Result()
                .setCode(ResultCode.FAIL)
                .setMsg(msg);
    }

    public static Result genAccessDeniedResult(String msg) {
        return new Result()
                .setCode(ResultCode.UNAUTHORIZED)
                .setMsg(msg);
    }
}
